
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:dio/dio.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      // 启动要显示的界面
      home: HomeContent(),
    );
  }
}

class HomeContent extends StatefulWidget {
  @override
  _HomeContentState createState() => _HomeContentState();
}

class _HomeContentState extends State<HomeContent> {

  void dioNetwork() async {

    // 1.创建dio网络请求对象
    final dio = Dio();

    // 2.发送网络请求
    final response = await dio.get('http://rest.apizza.net/mock/3bb78bf66bbd102a95221370ba9ddc2f/test');

    // 3.打印请求结果
    if (response.statusCode == HttpStatus.ok) {
      print(response.data);
    } else {
      print("请求失败：${response.statusCode}");
    }
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    dioNetwork();
  }
  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
    );
  }
}
